package cii_lib;

public class CCII_ACCESS_PARAM extends CCII_TABLE_INDEX{
  private CCII_TABLE_INDEX _Table;
  private CCII_COMPONENT _comp;
  public CCII_ACCESS_PARAM(CCII_TABLE_INDEX table, int inc, CCII_COMPONENT comp) {
    super(table,inc);
    _Table=table;
    _comp=comp;
    boolean Err=false;
    if (
	GetItem().CompID!=GetCompID()
	|| GetItem().Name==null || GetItem().Access!=CIIlib.TABLE_ACCESS.NA
	|| GetItem().Width<0 || GetItem().Number<1 || GetItem().Repeat<1
	|| (GetItem().Type!=CIIlib.TABLE_TYPE.IPAR && GetItem().Type!=CIIlib.TABLE_TYPE.LPAR &&  GetItem().Type!=CIIlib.TABLE_TYPE.HPAR
	    &&  GetItem().Type!=CIIlib.TABLE_TYPE.SPAR &&  GetItem().Type!=CIIlib.TABLE_TYPE.VPAR &&  GetItem().Type!=CIIlib.TABLE_TYPE.MPAR)
    )
      Err=true;
    int pos;
    for (int rep=0; rep<GetItem().Repeat; rep++)
      for (int num=0; num<GetItem().Number; num++){
	pos = rep*GetItem().Number+num;
	if (GetItem(pos).Address != num || GetItem(pos).Position != rep) {Err=true; break;}
	if ((GetItem(pos).Type==CIIlib.TABLE_TYPE.IPAR || GetItem(pos).Type==CIIlib.TABLE_TYPE.LPAR) && GetItem(pos).ParStrVal!=null) {Err=true; break;}
	if ((GetItem().Type==CIIlib.TABLE_TYPE.HPAR || GetItem().Type==CIIlib.TABLE_TYPE.SPAR || GetItem().Type==CIIlib.TABLE_TYPE.VPAR)
	    && GetItem(pos).ParIntVal!=-1 && GetItem(pos).ParStrVal==null) {Err=true; break;}
	if (GetItem().Type==CIIlib.TABLE_TYPE.MPAR && (GetItem(pos).ParIntVal<0 || GetItem(pos).ParStrVal==null)) {Err=true; break;}
      }
    if (Err)
      try {
	throw new CiiLibException("CCII_ACCESS_PARAM",CiiLibException.MSG.TABLE_ERROR);
      } catch (CiiLibException e) {e.printStackTrace();}
  }
  public boolean Exist()   {return((GetItem()==null || GetItem().Number==0)?false:true);};
  public String Name()     {return(GetItem().Name);};
  public String PathName() {return(CIIlib.PathCompName(_comp)+"."+GetItem().Name);};
  public int Number()      {return(GetItem().Number);};
  public int Repeat()      {return(GetItem().Repeat);};
  public CCII_TABLE_INDEX GetTable() {return(_Table);}
};
